package com.zd.composedemo.ui.compose

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.PointerEventType
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.zd.composedemo.R

@Preview(name = "testRow")
@Composable
fun RowLayout() {
    Row(
        horizontalArrangement = Arrangement.Center, //设置内容在水平方向上的排列方式
        verticalAlignment = Alignment.CenterVertically,//设置内容在垂直方向上的排列方式
        modifier = Modifier
            .fillMaxWidth()
            .height(160.dp)
            .background(Color.White)
            .padding(10.dp)

    ) {
        Image(
            painter = painterResource(R.drawable.baseline_robot_24),
            contentDescription = null,
            Modifier
                .background(Color.Gray, shape = CircleShape)
                .size(80.dp)
//                .aspectRatio(1f)
//                .clip(CircleShape)
                .align(Alignment.Top) //设置在父容器中交叉轴上的排列方式 会覆盖父容器设置的交叉轴排列方式
                .weight(1f)

        )
        Box(
            modifier = Modifier
                .weight(1f)
                .padding(5.dp)
                .fillMaxSize()
        ) {
            Spacer(
                modifier = Modifier
                    .matchParentSize()
//                    .background(Color.Gray)
            )

            Card(
                shape = RoundedCornerShape(10.dp),
                elevation = CardDefaults.cardElevation(2.dp),
                modifier = Modifier
                    .fillMaxSize()
            ) {
                Image(
                    painter = painterResource(R.drawable.ic_launcher_background),
                    contentDescription = null,
                    modifier = Modifier.fillMaxSize()
                )

            }

//            Text("boxView")
        }
        Image(
            painter = painterResource(R.drawable.baseline_robot_24),
            contentDescription = null,
            Modifier
                .padding(5.dp, 0.dp)
                .background(Color.Gray)
//                .clip(CircleShape)
//                .size(80.dp)
                .weight(1f)

        )
        Image(
            painter = painterResource(R.drawable.baseline_robot_24),
            contentDescription = null,
            Modifier
                .background(Color.Gray)
                .size(80.dp)
//                .padding(10.dp)
                .align(Alignment.Bottom)
                .weight(1f)

        )
    }
}

@Preview(showBackground = true)
@Composable
fun ColumnLayout(filter: PointerEventType? = null) {
    var log by remember { mutableStateOf("") }
    Column {
        Text(log)
        Box(
            Modifier
                .size(200.dp)
                .background(Color.Red)
                .pointerInput(filter) {
                    awaitPointerEventScope {
                        while (true) {
                            val event = awaitPointerEvent()
                            // handle pointer event
                            if (filter == null || event.type == filter) {
                                log = "${event.type}, ${event.changes.first().position}"
                            }
                        }
                    }
                }
        )
    }
}